﻿Imports System.IO

Public Class frmMain

    Const cActivated As String = "Activated"
    Const cDeactivated As String = "Deactivated"

    Dim oFileMng_UTIni As New FileMng_UTIni             ' To manage ini file
    Dim oFileMng_RCLog As New FileMng_RCLog             ' To manage RCLog file

    Dim blnFileMainModified As Boolean                  ' Indicates file main is modified
    Dim blnFileCategoryModified As Boolean              ' Indicate if file that contains category list is modified

    Dim strLastINIFile As String                        ' Path of last open ini file

    Enum ChangeCommand
        eChangeCommand_Activate = 0
        eChangeCommand_Deactivate = 1
        eChangeCommand_Switch = 2
    End Enum

#Region "Manage file"

    Private Sub OpenFile(ByVal inFileExt As String, ByVal inInitDir As String, ByVal inDialogTitle As String, ByRef outFilePath As String)
        Dim oOpenFileDialog As New System.Windows.Forms.OpenFileDialog

        With oOpenFileDialog
            .CheckFileExists = True
            .CheckPathExists = True
            .Filter = String.Format("File {0} (*.{0})|*.{0}", inFileExt)
            .InitialDirectory = inInitDir
            .Multiselect = False
            .Title = inDialogTitle
        End With

        If oOpenFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            outFilePath = oOpenFileDialog.FileName
            strLastINIFile = Path.GetDirectoryName(outFilePath)
        End If

        oOpenFileDialog = Nothing
    End Sub

    Private Sub SaveFile(ByVal inFileExt As String, ByVal inInitDir As String, ByVal inDialogTitle As String, ByVal inFileName As String, ByRef outFilePath As String)
        Dim oSaveFileDialog As New System.Windows.Forms.SaveFileDialog

        With oSaveFileDialog
            .CheckPathExists = True
            .Filter = String.Format("File {0} (*.{0})|*.{0}", inFileExt)
            .InitialDirectory = inInitDir
            .Title = inDialogTitle
            .FileName = inFileName
        End With

        If oSaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            outFilePath = oSaveFileDialog.FileName
        End If

        oSaveFileDialog = Nothing
    End Sub

    Private Function OpenFileINI(ByVal strFileINI As String, ByRef inFileINI_Mng As FileMng_UTIni) As Boolean
        If File.Exists(strFileINI) Then
            Dim readText() As String = File.ReadAllLines(strFileINI)

            Call CleanAllINI()
            If inFileINI_Mng.ReadFile(readText) Then
                strLastINIFile = strFileINI
                Call RefreshGridTestCases(inFileINI_Mng)
            Else
                Return False
            End If

            Return True
        Else
            Return False
        End If
    End Function

    Private Function OpenFileRCLog(ByVal strFileRCLog As String, ByRef inFileMng_RCLog As FileMng_RCLog) As Boolean
        If File.Exists(strFileRCLog) Then
            Dim readText() As String = File.ReadAllLines(strFileRCLog)

            Call CleanAllRCLog()
            If inFileMng_RCLog.ReadFile(readText) Then
                Call RefreshGridRCLog(inFileMng_RCLog)
            Else
                Return False
            End If

            Return True
        Else
            Return False
        End If
    End Function

#End Region

#Region "Utility Functions"

    Public Sub OnReceivDataTTY0(ByVal inData As String)
        txtConsole1.Text &= inData
        Me.Refresh()
    End Sub

    Public Sub OnOpenResults(ByVal inPath As String)
        webBrowser1.Navigate(inPath)
        Me.Refresh()
    End Sub

    Private Sub CheckFileMainIsModified()
        If blnFileMainModified Then
            blnFileMainModified = False

            If cboListFilesINI.SelectedIndex > -1 AndAlso cboListFilesINI.SelectedItem IsNot Nothing Then
                Dim item As NameValue = cboListFilesINI.SelectedItem
                Dim strDirMain As String = Path.GetDirectoryName(Path.GetDirectoryName(item.Name))
                Dim localFileINI_Mng As New FileMng_UTIni

                If LoadLocalFileMng_INI(strDirMain, item.Name, localFileINI_Mng) Then
                    If oFileMng_UTIni.MustSynchronize(localFileINI_Mng) Then
                        If MsgBox("File Main.c modified." & vbCrLf & "Do you want to synchronize INI file?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                            If Not SynchronizeINIFile(localFileINI_Mng, item.Name) Then
                                MsgBox(localFileINI_Mng.strErrorMsg, MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
                            End If
                        End If
                    End If
                Else
                    MsgBox(localFileINI_Mng.strErrorMsg, MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
                End If

                localFileINI_Mng = Nothing
            End If

        End If
    End Sub

    Private Sub CheckFileCategoryIsModified()
        If blnFileCategoryModified Then
            blnFileCategoryModified = False

            Dim localFileMng_RCLog As New FileMng_RCLog
            Dim strMainDirectory As String = GetSetting(My.Application.Info.AssemblyName, "Settings", "Host_MainDirectory", "")

            If LoadLocalFileMng_RCLog(strMainDirectory, localFileMng_RCLog) Then
                If oFileMng_RCLog.MustSynchronize(localFileMng_RCLog) Then
                    If MsgBox("File RCLogger.cfg modified." & vbCrLf & "Do you want to synchronize categories?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                        If Not SynchronizeRCLogFile(localFileMng_RCLog, strMainDirectory) Then
                            MsgBox(localFileMng_RCLog.strErrorMsg, MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
                        End If
                    End If
                End If
            Else
                MsgBox(localFileMng_RCLog.strErrorMsg, MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
            End If

            localFileMng_RCLog = Nothing

        End If
    End Sub

    Private Function Execute(ByVal inNameProject As String, ByVal inVariant As Integer) As Boolean
        ' Find project info using project name
        Dim oProjectInfo As ProjectInfo = Nothing
        oProjectInfo = glistProjectsInfo.Find(Function(inProjectInfo As ProjectInfo) As Boolean
                                                  Return inProjectInfo.strName = inNameProject
                                              End Function)
        If oProjectInfo Is Nothing Then
            MsgBox("Project not found.", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
            Return False
        End If

        txtConsole1.Text = ""
        tabControl.SelectedTab = tabConsole1
        Dim oLauncher As New Launcher(gVirtualMachine, oProjectInfo, inVariant)
        AddHandler oLauncher.OnReceiveDataToTTY0, AddressOf OnReceivDataTTY0
        AddHandler oLauncher.OnOpenResults, AddressOf OnOpenResults
        If oLauncher.LaunchUT() = False Then
            MsgBox(oLauncher.strErrorMsg)
        End If
        txtConsole1.Select(0, 0)

        oProjectInfo = Nothing
        oLauncher = Nothing

        Return True
    End Function

    Private Function GetMainFileName(ByVal inDirMain As String) As String
        Dim strFiles() As String = Directory.GetFiles(inDirMain, "*.c", SearchOption.TopDirectoryOnly)

        For Each lFile As String In strFiles
            If lFile.IndexOf("main", StringComparison.OrdinalIgnoreCase) > -1 Then
                Return Path.GetFileName(lFile)
                Exit For
            End If
        Next

        Return ""
    End Function

    Private Function LoadLocalFileMng_INI(ByVal inDirMain As String, ByVal inFileINI As String, ByRef inFileINI_Mng As FileMng_UTIni) As Boolean
        If Not Directory.Exists(inDirMain) Then
            Return False
        End If

        Dim strMainFileName As String = GetMainFileName(inDirMain)

        If strMainFileName = "" Then Return False
        If Not File.Exists(PutSlash(inDirMain) & strMainFileName) Then
            MsgBox("File Main.c not exist", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
            Return False
        End If

        Dim readText() As String = File.ReadAllLines(PutSlash(inDirMain) & strMainFileName)
        If inFileINI_Mng.ReadSourceFile(readText) Then
            inFileINI_Mng.strProjectName = Path.GetFileNameWithoutExtension(inFileINI)
            inFileINI_Mng.intVerbose = 1
            Return True
        Else
            Return False
        End If
    End Function

    Private Function LoadLocalFileMng_RCLog(ByVal inDirMain As String, ByRef inFileMng_RCLog As FileMng_RCLog) As Boolean
        If Not Directory.Exists(inDirMain) Then
            Return False
        End If

        Dim strFile As String = PutSlash(inDirMain) & "UTILS\Logger\Logger\RCLoggerDefs.h"

        If Not File.Exists(strFile) Then
            MsgBox("File RCLoggerDefs.h not exist", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
            Return False
        End If

        Dim readText() As String = File.ReadAllLines(strFile)
        If inFileMng_RCLog.ReadSourceFile(readText) Then
            Return True
        Else
            Return False
        End If
    End Function

    Private Function SynchronizeINIFile(ByRef inFileINI_Mng As FileMng_UTIni, ByVal inFileINI As String) As Boolean
        Call CleanAllINI()
        inFileINI_Mng.strProjectName = Path.GetFileNameWithoutExtension(inFileINI)
        inFileINI_Mng.intVerbose = 1
        oFileMng_UTIni = inFileINI_Mng

        If Not oFileMng_UTIni.SaveFile(inFileINI) Then
            Return False
        End If
        strLastINIFile = inFileINI
        Call RefreshGridTestCases(oFileMng_UTIni)

        Return True
    End Function

    Private Function SynchronizeRCLogFile(ByRef inFileMng_RCLog As FileMng_RCLog, ByVal inDirMain As String) As Boolean
        Dim strFile As String = PutSlash(inDirMain) & "UTILS\Logger\Logger\Cfg\RCLogger.cfg"
        Dim listCategory As New List(Of RCLogCategory)

        listCategory = oFileMng_RCLog.listCategories
        oFileMng_RCLog.listCategories.Clear()
        oFileMng_RCLog.listCategories = inFileMng_RCLog.listCategories

        For i As Integer = 0 To oFileMng_RCLog.listCategories.Count - 1
            For j As Integer = 0 To listCategory.Count - 1
                If listCategory(j).strName = oFileMng_RCLog.listCategories(i).strName Then
                    oFileMng_RCLog.listCategories(i) = listCategory(j)
                    Exit For
                End If
            Next
        Next

        listCategory = Nothing

        If Not oFileMng_RCLog.SaveFile(strFile) Then
            Return False
        End If
        Call RefreshGridTestCases(oFileMng_UTIni)

        Return True
    End Function

    Private Sub LoadCboINIFile()
        Dim listFile As New List(Of NameValue)

        For Each lProjectInfo As ProjectInfo In glistProjectsInfo
            listFile.Add(New NameValue(PutSlash(lProjectInfo.GetINIDir) & lProjectInfo.GetIniFileName, lProjectInfo.GetIniFileName))
        Next

        cboListFilesINI.DataSource = listFile
        cboListFilesINI.ValueMember = "Name"
        cboListFilesINI.DisplayMember = "Value"
        listFile = Nothing
    End Sub

    Private Sub RefreshGridTestCases(ByRef inFileMng_UTIni As FileMng_UTIni)
        ' Refresh grid information loading data from inFileMng_UTIni
        Dim dtTable As New DataTable
        Dim dtNewRow As DataRow

        dtTable.Columns.Add(New DataColumn("TestSuiteID", GetType(Integer)))
        dtTable.Columns.Add(New DataColumn("TestSuiteCode", GetType(String)))
        dtTable.Columns.Add(New DataColumn("TestSuiteName", GetType(String)))
        dtTable.Columns.Add(New DataColumn("TestSuiteValue", GetType(String)))
        dtTable.Columns.Add(New DataColumn("TestCaseID", GetType(Integer)))
        dtTable.Columns.Add(New DataColumn("TestCaseName", GetType(String)))
        dtTable.Columns.Add(New DataColumn("TestCaseValue", GetType(String)))
        dtTable.Columns.Add(New DataColumn("Status", GetType(String)))

        For i As Integer = 0 To inFileMng_UTIni.listTestSuites.Count - 1
            dtNewRow = dtTable.NewRow
            dtNewRow("TestSuiteID") = i
            dtNewRow("TestSuiteCode") = String.Format("[SUITE{0}]", Format(i + 1, "000"))
            dtNewRow("TestSuiteName") = inFileMng_UTIni.listTestSuites.Item(i).strName
            dtNewRow("TestSuiteValue") = inFileMng_UTIni.listTestSuites.Item(i).strValue
            dtNewRow("TestCaseID") = -1
            dtNewRow("TestCaseName") = ""
            dtNewRow("TestCaseValue") = ""
            dtNewRow("Status") = IIf(inFileMng_UTIni.listTestSuites(i).blnActivated, cActivated, cDeactivated)
            dtTable.Rows.Add(dtNewRow)
            For j As Integer = 0 To inFileMng_UTIni.listTestSuites(i).vettTestCases.Count - 1
                dtNewRow = dtTable.NewRow
                dtNewRow("TestSuiteID") = i
                dtNewRow("TestSuiteName") = ""
                dtNewRow("TestSuiteValue") = ""
                dtNewRow("TestCaseID") = j
                dtNewRow("TestCaseName") = inFileMng_UTIni.listTestSuites(i).vettTestCases(j).strName
                dtNewRow("TestCaseValue") = inFileMng_UTIni.listTestSuites(i).vettTestCases(j).strValue
                dtNewRow("Status") = IIf(inFileMng_UTIni.listTestSuites(i).vettTestCases(j).blnActivated, cActivated, cDeactivated)

                dtTable.Rows.Add(dtNewRow)
            Next
        Next

        grdTestCases.DataSource = dtTable
        grdTestCases.Columns("TestSuiteCode").HeaderText = "TestSuite ID"
        grdTestCases.Columns("TestSuiteName").HeaderText = "Test Suite"
        grdTestCases.Columns("TestCaseName").HeaderText = "Test Case"

        grdTestCases.Columns("TestSuiteID").Visible = False
        grdTestCases.Columns("TestCaseID").Visible = False
        grdTestCases.Columns("TestSuiteValue").Visible = False
        grdTestCases.Columns("TestCaseValue").Visible = False

        grdTestCases.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
        For Each lColumn As DataGridViewColumn In grdTestCases.Columns
            lColumn.SortMode = DataGridViewColumnSortMode.NotSortable
        Next

        dtTable = Nothing
    End Sub

    Private Sub RefreshGridRCLog(ByRef inFileMng_RCLog As FileMng_RCLog)
        ' Refresh grid information loading data from inFileMng_RCLog
        Dim dtTable As New DataTable
        Dim dtNewRow As DataRow

        dtTable.Columns.Add(New DataColumn("CategoryID", GetType(Integer)))
        dtTable.Columns.Add(New DataColumn("Category", GetType(String)))
        dtTable.Columns.Add(New DataColumn("PriorityID", GetType(Integer)))
        dtTable.Columns.Add(New DataColumn("Priority", GetType(String)))
        dtTable.Columns.Add(New DataColumn("AppenderID", GetType(Integer)))
        dtTable.Columns.Add(New DataColumn("Appender", GetType(String)))

        For i As Integer = 0 To inFileMng_RCLog.listCategories.Count - 1
            dtNewRow = dtTable.NewRow
            dtNewRow("CategoryID") = i
            dtNewRow("Category") = inFileMng_RCLog.listCategories(i).strName
            dtNewRow("Priority") = inFileMng_RCLog.listCategories(i).GetPriority
            dtNewRow("PriorityID") = inFileMng_RCLog.listCategories(i).intPriority
            dtNewRow("AppenderID") = 0
            dtNewRow("Appender") = inFileMng_RCLog.listCategories(i).strAppender.ToString
            dtTable.Rows.Add(dtNewRow)
        Next

        grdRCLog.DataSource = dtTable

        grdRCLog.Columns("CategoryID").Visible = False
        grdRCLog.Columns("AppenderID").Visible = False
        grdRCLog.Columns("PriorityID").Visible = False

        grdRCLog.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells

        dtTable = Nothing
    End Sub

    Private Sub ChangeAppender(ByVal inRow As Integer, ByVal inKeys As Keys, ByRef inFileMng_RCLog As FileMng_RCLog)
        ' Change priority
        Dim intCategoryID As Integer = CInt(grdRCLog.Rows(inRow).Cells("CategoryID").Value)
        Dim strAppender As String = ""

        Select Case inKeys
            Case Keys.D0
                strAppender = "/dev/ttyp0"
            Case Keys.D1
                strAppender = "/dev/ttyp1"
            Case Keys.D2
                strAppender = "/dev/ttyp2"
            Case Keys.D3
                strAppender = "/dev/ttyp3"
            Case Keys.D4
                strAppender = "/dev/ttyp4"
            Case Keys.D5
                strAppender = "/dev/ttyp5"
            Case Keys.D6
                strAppender = "/dev/ttyp6"
            Case Keys.D7
                strAppender = "/dev/ttyp7"
            Case Keys.D8
                strAppender = "/dev/ttyp8"
            Case Keys.D9
                strAppender = "/dev/ttyp9"
            Case Else
                Return
        End Select

        grdRCLog.Rows(inRow).Cells("Appender").Value = strAppender
        inFileMng_RCLog.listCategories(intCategoryID).strAppender = strAppender

        lblUpdateStatusRCLog.Text = "Upload to do"
        lblUpdateStatusRCLog.ForeColor = Color.Red
    End Sub

    Private Sub ChangePriority(ByVal inRow As Integer, ByVal inKeys As Keys, ByRef inFileMng_RCLog As FileMng_RCLog)
        ' Change priority
        Dim intCategoryID As Integer = CInt(grdRCLog.Rows(inRow).Cells("CategoryID").Value)
        Dim intPriority As Integer
        Dim strPriority As String = ""
        Dim oColor As Color

        Select Case inKeys
            Case Keys.F
                intPriority = RCLogCategory.Priority.ePriority_FATAL
                strPriority = "FATAL"
                oColor = Color.DarkRed
            Case Keys.E
                intPriority = RCLogCategory.Priority.ePriority_ERROR
                strPriority = "ERROR"
                oColor = Color.Red
            Case Keys.W
                intPriority = RCLogCategory.Priority.ePriority_WARN
                strPriority = "WARN"
                oColor = Color.Orange
            Case Keys.I
                intPriority = RCLogCategory.Priority.ePriority_INFO
                strPriority = "INFO"
                oColor = Color.Green
            Case Keys.D
                intPriority = RCLogCategory.Priority.ePriority_DEBUG
                strPriority = "DEBUG"
                oColor = Color.Blue
            Case Keys.T
                intPriority = RCLogCategory.Priority.ePriority_TRACE
                strPriority = "TRACE"
                oColor = Color.Aqua
            Case Else
                Return
        End Select

        grdRCLog.Rows(inRow).Cells("PriorityID").Value = intPriority
        grdRCLog.Rows(inRow).Cells("Priority").Value = strPriority
        grdRCLog.Rows(inRow).Cells("Priority").Style.ForeColor = oColor

        inFileMng_RCLog.listCategories(intCategoryID).intPriority = intPriority

        lblUpdateStatusRCLog.Text = "Upload to do"
        lblUpdateStatusRCLog.ForeColor = Color.Red
    End Sub

    Private Sub ChangeStatusTest(ByVal inRow As Integer, ByVal inCol As Integer, ByRef inFileMng_UTIni As FileMng_UTIni)
        ' Change status of test/suite in grid and in fileManager
        Dim intTestSuiteID As Integer = CInt(grdTestCases.Rows(inRow).Cells("TestSuiteID").Value)
        Dim intTestCaseID As Integer = CInt(grdTestCases.Rows(inRow).Cells("TestCaseID").Value)

        ' change color
        If grdTestCases.Rows(inRow).Cells(inCol).Value = cActivated Then
            grdTestCases.Rows(inRow).Cells(inCol).Value = cDeactivated
            grdTestCases.Rows(inRow).Cells(inCol).Style.ForeColor = Color.Red
        Else
            grdTestCases.Rows(inRow).Cells(inCol).Value = cActivated
            grdTestCases.Rows(inRow).Cells(inCol).Style.ForeColor = Color.Green
        End If

        ' change value based on row type
        If intTestCaseID = -1 Then
            ' change test suite
            inFileMng_UTIni.listTestSuites(intTestSuiteID).blnActivated = Not inFileMng_UTIni.listTestSuites(intTestSuiteID).blnActivated

            Dim oColor As Color = Color.White
            If inFileMng_UTIni.listTestSuites(intTestSuiteID).blnActivated Then
                oColor = Color.White
            Else
                oColor = Color.Gray
            End If
            For i As Integer = 0 To grdTestCases.Rows.Count - 1
                If grdTestCases.Rows(i).Cells("TestSuiteID").Value = intTestSuiteID And grdTestCases.Rows(i).Cells("TestCaseID").Value <> -1 Then
                    grdTestCases.Rows(i).DefaultCellStyle.BackColor = oColor
                End If
            Next
        Else
            ' change test case
            inFileMng_UTIni.listTestSuites(intTestSuiteID).vettTestCases(intTestCaseID).blnActivated = Not inFileMng_UTIni.listTestSuites(intTestSuiteID).vettTestCases(intTestCaseID).blnActivated
        End If

        lblUpdateStatusFileINI.Text = "Upload to do"
        lblUpdateStatusFileINI.ForeColor = Color.Red
    End Sub

    Private Sub RefreshINIFile(ByRef inFileMng_UTIni As FileMng_UTIni)
        If optAutoRefreshActivated.Checked And strLastINIFile <> "" Then
            Call inFileMng_UTIni.SaveFile(strLastINIFile)
        End If
    End Sub

    Private Sub ChangeStatusAllSuites(ByVal inChageCommand As ChangeCommand, ByRef inFileMng_UTIni As FileMng_UTIni)
        Dim strCurrStatus As String = ""

        Me.Cursor = Cursors.WaitCursor

        If Not inChageCommand = ChangeCommand.eChangeCommand_Switch Then
            strCurrStatus = IIf(inChageCommand = ChangeCommand.eChangeCommand_Activate, cDeactivated, cActivated)
        End If

        For i As Integer = 0 To grdTestCases.Rows.Count - 1
            If grdTestCases.Rows(i).Cells("TestCaseID").Value = -1 Then
                ' test suite row
                If inChageCommand = ChangeCommand.eChangeCommand_Switch Then
                    Call ChangeStatusTest(i, grdTestCases.Columns.Count - 1, inFileMng_UTIni)
                Else
                    If grdTestCases.Rows(i).Cells(grdTestCases.Columns.Count - 1).Value = strCurrStatus Then
                        Call ChangeStatusTest(i, grdTestCases.Columns.Count - 1, inFileMng_UTIni)
                    End If
                End If
            End If
        Next

        Me.Cursor = Cursors.Default
    End Sub

    Private Sub ChangeStatusAllTests(ByVal inChageCommand As ChangeCommand, ByVal inSuiteID As Integer, ByRef inFileMng_UTIni As FileMng_UTIni)
        Dim strCurrStatus As String = ""

        Me.Cursor = Cursors.WaitCursor

        If Not inChageCommand = ChangeCommand.eChangeCommand_Switch Then
            strCurrStatus = IIf(inChageCommand = ChangeCommand.eChangeCommand_Activate, cDeactivated, cActivated)
        End If

        For i As Integer = 0 To grdTestCases.Rows.Count - 1
            If grdTestCases.Rows(i).Cells("TestCaseID").Value <> -1 And
               (inSuiteID = 0 Or grdTestCases.Rows(i).Cells("TestSuiteID").Value = inSuiteID) Then
                ' test case row
                If inChageCommand = ChangeCommand.eChangeCommand_Switch Then
                    Call ChangeStatusTest(i, grdTestCases.Columns.Count - 1, inFileMng_UTIni)
                Else
                    If grdTestCases.Rows(i).Cells(grdTestCases.Columns.Count - 1).Value = strCurrStatus Then
                        Call ChangeStatusTest(i, grdTestCases.Columns.Count - 1, inFileMng_UTIni)
                    End If
                End If
            End If
        Next

        Me.Cursor = Cursors.Default
    End Sub

#End Region

#Region "Commands"

    Private Sub cmdUploadFileRCLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUploadFileRCLog.Click
        Try
            If gVirtualMachine.strIP <> "" Then
                Dim strNameFile As String = "RCLogger.cfg"
                Dim strFile As String = PutSlash(My.Computer.FileSystem.SpecialDirectories.Temp) & "tempRCLog.cfg"
                If Not oFileMng_RCLog.SaveFile(strFile) Then
                    MsgBox(oFileMng_RCLog.strErrorMsg, MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
                    Return
                End If

                Dim oFTPclient As New FTPclient(gVirtualMachine.strIP, gVirtualMachine.strUsername, gVirtualMachine.strPassword)

                Me.Cursor = Cursors.WaitCursor

                If oFTPclient.Upload(strFile, "/" & strNameFile) Then
                    lblUpdateStatusRCLog.Text = "Done " & Now.Hour & ":" & Now.Minute
                    lblUpdateStatusRCLog.ForeColor = Color.Green
                Else
                    MsgBox("Impossible upload to target", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
                End If

                oFTPclient = Nothing
            Else
                MsgBox("Set Target information", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
            End If
        Catch ex As Exception
            MsgBox("Error to upload file in target", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
        Finally
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub cmdUploadFileINI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUploadFileINI.Click
        Try
            If (cboListFilesINI.SelectedIndex > -1 AndAlso cboListFilesINI.SelectedItem IsNot Nothing) Or strLastINIFile <> "" Then
                If gVirtualMachine.strIP <> "" Then
                    Dim strNameFile As String = ""
                    Dim strFileINI As String = PutSlash(My.Computer.FileSystem.SpecialDirectories.Temp) & "tempIni.ini"
                    Call oFileMng_UTIni.SaveFile(strFileINI)

                    Dim oFTPclient As New FTPclient(gVirtualMachine.GetIPForFTP, gVirtualMachine.strUsername, gVirtualMachine.strPassword)

                    Me.Cursor = Cursors.WaitCursor
                    If cboListFilesINI.SelectedIndex > -1 Then
                        strNameFile = CType(cboListFilesINI.SelectedItem, NameValue).Value
                    Else
                        strNameFile = Path.GetFileName(strLastINIFile)
                    End If

                    If oFTPclient.Upload(strFileINI, "/" & strNameFile) Then
                        lblUpdateStatusFileINI.Text = "Done " & Now.Hour & ":" & Now.Minute
                        lblUpdateStatusFileINI.ForeColor = Color.Green
                    Else
                        MsgBox("Impossible upload to target", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
                    End If

                    oFTPclient = Nothing
                Else
                    MsgBox("Set Target information", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
                End If
            Else
                MsgBox("Select INI file", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
            End If
        Catch ex As Exception
            MsgBox("Error to upload file in target", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
        Finally
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub cmdSynchronizeRCLogFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSynchronizeRCLogFile.Click
        Try
            Me.Cursor = Cursors.WaitCursor

            Dim localFileMng_RCLog As New FileMng_RCLog
            Dim strMainDirectory As String = GetSetting(My.Application.Info.AssemblyName, "Settings", "Host_MainDirectory", "")

            If LoadLocalFileMng_RCLog(strMainDirectory, localFileMng_RCLog) Then
                Call SynchronizeRCLogFile(localFileMng_RCLog, strMainDirectory)
            Else
                MsgBox(localFileMng_RCLog.strErrorMsg, MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
            End If

            localFileMng_RCLog = Nothing
        Catch ex As Exception
            MsgBox("Error to synchronize", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
        Finally
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub cmdSynchronizeINIFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSynchronizeINIFile.Click
        Try
            If cboListFilesINI.SelectedIndex > -1 AndAlso cboListFilesINI.SelectedItem IsNot Nothing Then
                Me.Cursor = Cursors.WaitCursor
                Dim item As NameValue = cboListFilesINI.SelectedItem
                Dim strDirMain As String = Path.GetDirectoryName(Path.GetDirectoryName(item.Name))
                Dim localFileINI_Mng As New FileMng_UTIni

                If LoadLocalFileMng_INI(strDirMain, item.Name, localFileINI_Mng) Then
                    Call SynchronizeINIFile(localFileINI_Mng, item.Name)
                Else
                    MsgBox(localFileINI_Mng.strErrorMsg, MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
                End If

                localFileINI_Mng = Nothing
                mainFileWatcher.Path = Path.GetDirectoryName(Path.GetDirectoryName(item.Name))
            End If
        Catch ex As Exception
            MsgBox("Error to synchronize", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
        Finally
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub cmdExecuteRelease_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExecuteRelease.Click
        Try
            If cboListFilesINI.SelectedIndex > -1 AndAlso cboListFilesINI.SelectedItem IsNot Nothing Then
                Me.Cursor = Cursors.WaitCursor
                Dim item As NameValue = cboListFilesINI.SelectedItem

                Call Execute(item.Value.Substring(0, item.Value.Length - 4), Launcher.ExecVariant.eExecVariant_RELEASE)

            End If
        Catch ex As Exception
            MsgBox("Error to Execute RELEASE", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
        Finally
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub cmdExecuteTrace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExecuteTrace.Click
        Try
            If cboListFilesINI.SelectedIndex > -1 AndAlso cboListFilesINI.SelectedItem IsNot Nothing Then
                Me.Cursor = Cursors.WaitCursor
                Dim item As NameValue = cboListFilesINI.SelectedItem

                Call Execute(item.Value.Substring(0, item.Value.Length - 4), Launcher.ExecVariant.eExecVariant_TRACE)

            End If
        Catch ex As Exception
            MsgBox("Error to Execute TRACE", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
        Finally
            Me.Cursor = Cursors.Default
        End Try
    End Sub

#End Region

#Region "Menu"

    Private Sub cmdGenerateINIFromMain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuGenerateIniFromMain.Click
        Try
            Dim strFileMain As String = ""
            Dim strFileINI As String = ""

            Call OpenFile("c", GetInitDir(strLastINIFile), "Select file Main.c", strFileMain)

            If strFileMain <> "" Then
                Dim strDirName As String = Path.GetDirectoryName(strFileMain)
                Dim split As String() = strDirName.Split("\")
                strDirName = split(split.Length - 1)

                cboListFilesINI.SelectedIndex = -1
                Call CleanAllINI()
                Dim readText() As String = File.ReadAllLines(strFileMain)
                If oFileMng_UTIni.ReadSourceFile(readText) Then
                    oFileMng_UTIni.strProjectName = strDirName
                    oFileMng_UTIni.intVerbose = 1

                    Call RefreshGridTestCases(oFileMng_UTIni)
                    optAutoRefreshActivated.Checked = False
                Else
                    MsgBox(oFileMng_UTIni.strErrorMsg, MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
                End If
            End If
        Catch ex As Exception
            MsgBox("Error to generate file INI.", vbCritical)
        End Try
    End Sub

    Private Sub mnuOpenINI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpenINI.Click
        Try
            Dim strFileINI As String = ""

            Call OpenFile("ini", GetInitDir(strLastINIFile), "Select file INI", strFileINI)
            If strFileINI <> "" Then
                cboListFilesINI.SelectedIndex = -1

                If Not OpenFileINI(strFileINI, oFileMng_UTIni) Then
                    MsgBox("File INI not exist", vbCritical, My.Application.Info.AssemblyName)
                End If

            End If
        Catch ex As Exception
            MsgBox("Error to load file INI", vbCritical, My.Application.Info.AssemblyName)
        End Try
    End Sub

    Private Sub mnuSaveINI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSaveINI.Click
        Try
            Dim strFileINI As String = ""

            Call SaveFile("ini", GetInitDir(strLastINIFile), "Save file INI", oFileMng_UTIni.strProjectName, strFileINI)
            strLastINIFile = Path.GetDirectoryName(strFileINI)
            If strFileINI <> "" Then
                If Not oFileMng_UTIni.SaveFile(strFileINI) Then
                    MsgBox(oFileMng_UTIni.strErrorMsg, MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
                    Return
                End If
                strLastINIFile = strFileINI
            End If
        Catch ex As Exception
            MsgBox("Error to save file INI", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
        End Try
    End Sub

    Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click
        Dim oForm As New frmAbout
        oForm.ShowDialog()
        oForm = Nothing
    End Sub

    Private Sub mnuViewHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewHelp.Click
        MsgBox("Come on you dont need help....i know you can! XD")
    End Sub

#Region "Grid test cases Menu"

    Private Sub mnuActivateAllSuites_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuActivateAllSuites.Click
        Call ChangeStatusAllSuites(ChangeCommand.eChangeCommand_Activate, oFileMng_UTIni)
        Call RefreshINIFile(oFileMng_UTIni)
    End Sub

    Private Sub mnuDeactivateAllSuites_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDeactivateAllSuites.Click
        Call ChangeStatusAllSuites(ChangeCommand.eChangeCommand_Deactivate, oFileMng_UTIni)
        Call RefreshINIFile(oFileMng_UTIni)
    End Sub

    Private Sub mnuActivateAllCases_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuActivateAllCases.Click
        Call ChangeStatusAllTests(ChangeCommand.eChangeCommand_Activate, 0, oFileMng_UTIni)
        Call RefreshINIFile(oFileMng_UTIni)
    End Sub

    Private Sub mnuDeactivateAllCases_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDeactivateAllCases.Click
        Call ChangeStatusAllTests(ChangeCommand.eChangeCommand_Deactivate, 0, oFileMng_UTIni)
        Call RefreshINIFile(oFileMng_UTIni)
    End Sub

    Private Sub mnuActivateAllTestInSuite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuActivateAllTestInSuite.Click
        If grdTestCases.SelectedRows.Count > 0 Then
            Dim intSuiteID As Integer = grdTestCases.SelectedRows(0).Cells("TestSuiteID").Value

            Call ChangeStatusAllTests(ChangeCommand.eChangeCommand_Activate, intSuiteID, oFileMng_UTIni)
            Call RefreshINIFile(oFileMng_UTIni)
        End If
    End Sub

    Private Sub mnuDeactivateAllTestInSuite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDeactivateAllTestInSuite.Click
        If grdTestCases.SelectedRows.Count > 0 Then
            Dim intSuiteID As Integer = grdTestCases.SelectedRows(0).Cells("TestSuiteID").Value

            Call ChangeStatusAllTests(ChangeCommand.eChangeCommand_Deactivate, intSuiteID, oFileMng_UTIni)
            Call RefreshINIFile(oFileMng_UTIni)
        End If
    End Sub

    Private Sub mnuSwitchTestInSuite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSwitchTestInSuite.Click
        If grdTestCases.SelectedRows.Count > 0 Then
            Dim intSuiteID As Integer = grdTestCases.SelectedRows(0).Cells("TestSuiteID").Value

            Call ChangeStatusAllTests(ChangeCommand.eChangeCommand_Switch, intSuiteID, oFileMng_UTIni)
            Call RefreshINIFile(oFileMng_UTIni)
        End If
    End Sub

    Private Sub mnuSwitchAllTestCases_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSwitchAllTestCases.Click
        Call ChangeStatusAllTests(ChangeCommand.eChangeCommand_Switch, 0, oFileMng_UTIni)
        Call RefreshINIFile(oFileMng_UTIni)
    End Sub

    Private Sub mnuSwitchAllTestSuites_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSwitchAllTestSuites.Click
        Call ChangeStatusAllSuites(ChangeCommand.eChangeCommand_Switch, oFileMng_UTIni)
        Call RefreshINIFile(oFileMng_UTIni)
    End Sub

#End Region

    Private Sub mnuSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSettings.Click
        Dim oForm As New frmSettings
        oForm.ShowDialog()
        oForm = Nothing
        Call LoadCboINIFile()
    End Sub

#End Region

#Region "Grid TestCases"

    Private Sub grdTestCases_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grdTestCases.CellDoubleClick
        Try
            If grdTestCases.DataSource IsNot Nothing Then
                Call ChangeStatusTest(e.RowIndex, grdTestCases.ColumnCount - 1, oFileMng_UTIni)
                Call RefreshINIFile(oFileMng_UTIni)
            End If
        Catch ex As Exception
            MsgBox("Impossible to modify data", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
        End Try
    End Sub

    Private Sub grdTestCases_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles grdTestCases.CellMouseClick
        If e.RowIndex >= 0 And e.ColumnIndex >= 0 And e.Button = MouseButtons.Right Then
            grdTestCases.ClearSelection()
            grdTestCases.Rows(e.RowIndex).Selected = True
            mnuGriglia.Show(MousePosition)
        End If
    End Sub

    Private Sub grdTestCases_DataBindingComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) Handles grdTestCases.DataBindingComplete
        For Each lRow As DataGridViewRow In grdTestCases.Rows
            If lRow.Cells("Status").Value = cActivated Then
                lRow.Cells("Status").Style.ForeColor = Color.Green
            Else
                lRow.Cells("Status").Style.ForeColor = Color.Red
                If CInt(lRow.Cells("TestCaseID").Value) = -1 Then
                    Dim intTestSuiteID As Integer = CInt(lRow.Cells("TestSuiteID").Value)
                    For i As Integer = 0 To grdTestCases.Rows.Count - 1
                        If grdTestCases.Rows(i).Cells("TestSuiteID").Value = intTestSuiteID And grdTestCases.Rows(i).Cells("TestCaseID").Value <> -1 Then
                            grdTestCases.Rows(i).DefaultCellStyle.BackColor = Color.Gray
                        End If
                    Next
                End If
            End If
        Next
    End Sub

    Private Sub grdTestCases_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles grdTestCases.KeyDown
        If e.KeyCode = Keys.Space Then
            If grdTestCases.SelectedCells.Count > 0 Then
                Call ChangeStatusTest(grdTestCases.SelectedCells(0).RowIndex, grdTestCases.ColumnCount - 1, oFileMng_UTIni)
                Call RefreshINIFile(oFileMng_UTIni)
            End If
        End If
    End Sub

#End Region

#Region "Grid RCLog"

    Private Sub grdRCLog_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles grdRCLog.KeyDown
        If grdRCLog.SelectedCells.Count > 0 Then
            If e.KeyCode = Keys.F Or
                e.KeyCode = Keys.W Or
                e.KeyCode = Keys.E Or
                e.KeyCode = Keys.I Or
                e.KeyCode = Keys.D Or
                e.KeyCode = Keys.T Then
                Call ChangePriority(grdRCLog.SelectedCells(0).RowIndex, e.KeyCode, oFileMng_RCLog)
            ElseIf e.KeyCode = Keys.D0 Or
                e.KeyCode = Keys.D1 Or
                e.KeyCode = Keys.D2 Or
                e.KeyCode = Keys.D3 Or
                e.KeyCode = Keys.D4 Or
                e.KeyCode = Keys.D5 Or
                e.KeyCode = Keys.D6 Or
                e.KeyCode = Keys.D7 Or
                e.KeyCode = Keys.D8 Or
                e.KeyCode = Keys.D9 Then
                Call ChangeAppender(grdRCLog.SelectedCells(0).RowIndex, e.KeyCode, oFileMng_RCLog)
            End If
        End If
    End Sub

    Private Sub grdRCLog_Sorted(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdRCLog.Sorted
        If grdRCLog.SortedColumn.Name = "Priority" Then

            If grdRCLog.Columns("PriorityID").Tag = SortOrder.Ascending Then
                grdRCLog.Sort(grdRCLog.Columns("PriorityID"), System.ComponentModel.ListSortDirection.Descending)
                grdRCLog.Columns("PriorityID").Tag = SortOrder.Descending
            Else
                grdRCLog.Sort(grdRCLog.Columns("PriorityID"), System.ComponentModel.ListSortDirection.Ascending)
                grdRCLog.Columns("PriorityID").Tag = SortOrder.Ascending
            End If

        End If
    End Sub

    Private Sub grdRCLog_DataBindingComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) Handles grdRCLog.DataBindingComplete
        Dim vettColor(6) As Color

        ' Load color vector 
        vettColor(RCLogCategory.Priority.ePriority_FATAL - 1) = Color.DarkRed
        vettColor(RCLogCategory.Priority.ePriority_ERROR - 1) = Color.Red
        vettColor(RCLogCategory.Priority.ePriority_WARN - 1) = Color.Orange
        vettColor(RCLogCategory.Priority.ePriority_INFO - 1) = Color.Green
        vettColor(RCLogCategory.Priority.ePriority_DEBUG - 1) = Color.Blue
        vettColor(RCLogCategory.Priority.ePriority_TRACE - 1) = Color.Aqua

        For Each lRow As DataGridViewRow In grdRCLog.Rows
            If lRow.Cells("PriorityID").Value IsNot Nothing Then
                lRow.Cells("Priority").Style.ForeColor = vettColor(CInt(lRow.Cells("PriorityID").Value) - 1)
            End If
        Next
    End Sub

#End Region

#Region "Clean"

    Private Sub CleanAllINI()
        grdTestCases.DataSource = Nothing
        oFileMng_UTIni.Clear()
        lblUpdateStatusFileINI.Text = ""
        strLastINIFile = My.Computer.FileSystem.SpecialDirectories.Desktop
    End Sub

    Private Sub CleanAllRCLog()
        grdRCLog.DataSource = Nothing
        oFileMng_RCLog.Clear()
        lblUpdateStatusRCLog.Text = ""
    End Sub

    Private Sub CleanAl()
        Call CleanAllINI()
        Call CleanAllRCLog()
    End Sub

#End Region

#Region "Cbo"

    Private Sub cboListFilesINI_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cboListFilesINI.KeyDown
        If e.KeyCode = Keys.F5 Then
            Call LoadCboINIFile()
        End If
    End Sub

    Private Sub cboListFilesINI_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboListFilesINI.SelectedIndexChanged
        If cboListFilesINI.SelectedIndex > -1 AndAlso cboListFilesINI.SelectedItem IsNot Nothing Then
            Dim item As NameValue = cboListFilesINI.SelectedItem
            Dim strDirMain As String = Path.GetDirectoryName(Path.GetDirectoryName(item.Name))

            If Not OpenFileINI(item.Name, oFileMng_UTIni) Then
                MsgBox("File INI not exist", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
            End If

            Dim localFileINI_Mng As New FileMng_UTIni
            If LoadLocalFileMng_INI(strDirMain, item.Name, localFileINI_Mng) Then
                If oFileMng_UTIni.MustSynchronize(localFileINI_Mng) Then
                    If MsgBox("File Main.c modified." & vbCrLf & "Do you want to synchronize INI file?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                        If Not SynchronizeINIFile(localFileINI_Mng, item.Name) Then
                            MsgBox(localFileINI_Mng.strErrorMsg, MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
                        End If
                    End If
                End If
            Else
                MsgBox(localFileINI_Mng.strErrorMsg, MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
            End If
            localFileINI_Mng = Nothing

            If Directory.Exists(item.Name) Then
                mainFileWatcher.Path = Path.GetDirectoryName(Path.GetDirectoryName(item.Name))
            End If

        End If
    End Sub

#End Region

#Region "Console"

    Private Sub txtConsole_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtConsole1.TextChanged
        Dim txtConsole As TextBox = CType(sender, TextBox)

        If txtConsole.Text.Length > 0 Then
            txtConsole.Select(txtConsole.Text.Length - 1, 0)
            txtConsole.ScrollToCaret()
        End If
    End Sub

#End Region

#Region "FileWatcher"

    Private Sub mainFileWatcher_Changed(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles mainFileWatcher.Changed
        If e.Name.IndexOf("main", StringComparison.OrdinalIgnoreCase) > -1 Then
            blnFileMainModified = True
        End If
    End Sub

    Private Sub categoryFileWatcher_Changed(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles categoryFileWatcher.Changed
        If e.Name.IndexOf("RCLoggerDefs.h") > -1 Then
            blnFileCategoryModified = True
        End If
    End Sub

#End Region

#Region "Form events"

    Private Sub frmMain_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        Call CheckFileMainIsModified()
        Call CheckFileCategoryIsModified()
        cboListFilesINI.Focus()
    End Sub

    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim strMainDirectory As String = GetSetting(My.Application.Info.AssemblyName, "Settings", "Host_MainDirectory", "")

        If strMainDirectory <> "" Then
            ' Load cbo with file INI info
            Call LoadCboINIFile()
            cboListFilesINI.SelectedIndex = -1
            grdTestCases.DataSource = Nothing

            ' Load RCLog
            If Not OpenFileRCLog(PutSlash(strMainDirectory) & "UTILS\Logger\Logger\Cfg\RCLogger.cfg", oFileMng_RCLog) Then
                MsgBox(oFileMng_RCLog.strErrorMsg, MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
            End If

            ' Set path for categoryFileWatcher
            categoryFileWatcher.Path = PutSlash(strMainDirectory) & "UTILS\Logger\Logger\"
        Else
            MsgBox("Set Host main directory", MsgBoxStyle.Critical, My.Application.Info.AssemblyName)
        End If

    End Sub

#End Region

End Class
